home *** CD-ROM | disk | FTP | other *** search
/ Internet Info 1994 March / Internet Info CD-ROM (Walnut Creek) (March 1994).iso / networking / ip / ka9q / src890906.arc / ICMPDUMP.C < prev    next >
C/C++ Source or Header  |  1989-08-11  |  1KB  |  65 lines

  1. #include <stdio.h>
  2. #include "global.h"
  3. #include "mbuf.h"
  4. #include "internet.h"
  5. #include "icmp.h"
  6. #include "trace.h"
  7. #include "ip.h"
  8.  
  9. /* Dump an ICMP header */
  10. void
  11. icmp_dump(bpp,source,dest,check)
  12. struct mbuf **bpp;
  13. int32 source,dest;
  14. int check;        /* If 0, bypass checksum verify */
  15. {
  16.     struct icmp icmp;
  17.     int16 csum;
  18.  
  19.     if(bpp == NULLBUFP || *bpp == NULLBUF)
  20.         return;
  21.     csum = cksum(NULLHEADER,*bpp,len_mbuf(*bpp));
  22.     
  23.     ntohicmp(&icmp,bpp);
  24.     
  25.     printf("ICMP: type %s",smsg(Icmptypes,ICMP_TYPES,uchar(icmp.type)));
  26.  
  27.     switch(uchar(icmp.type)){
  28.     case DEST_UNREACH:
  29.         printf(" code %s",smsg(Unreach,NUNREACH,uchar(icmp.code)));
  30.         break;
  31.     case REDIRECT:
  32.         printf(" code %s",smsg(Redirect,NREDIRECT,uchar(icmp.code)));
  33.         break;
  34.     case TIME_EXCEED:
  35.         printf(" code %s",smsg(Exceed,NEXCEED,uchar(icmp.code)));
  36.         break;
  37.     case PARAM_PROB:
  38.         printf(" pointer %u",icmp.args.pointer);
  39.         break;
  40.     case ECHO:
  41.     case ECHO_REPLY:
  42.     case INFO_RQST:
  43.     case INFO_REPLY:
  44.     case TIMESTAMP:
  45.     case TIME_REPLY:
  46.         printf(" id %u seq %u",icmp.args.echo.id,icmp.args.echo.seq);
  47.         break;
  48.     }
  49.     if(check && csum != 0){
  50.         printf(" CHECKSUM ERROR (%u)",csum);
  51.     }
  52.     printf("\n");
  53.     /* Dump the offending IP header, if any */
  54.     switch(icmp.type){
  55.     case DEST_UNREACH:
  56.     case TIME_EXCEED:
  57.     case PARAM_PROB:
  58.     case QUENCH:
  59.     case REDIRECT:
  60.         printf("Returned ");
  61.         ip_dump(bpp,0);
  62.     }
  63. }
  64.  
  65.